package com.tengju.user.infrastructure.repository.convert;

import com.tengju.user.domain.model.sign.StarBlacklist;
import com.tengju.user.domain.model.sign.StarBlacklistId;
import com.tengju.user.domain.model.sign.StarBlacklistValidStatusEnum;
import com.tengju.user.domain.model.user.StarLevelEnum;
import com.tengju.user.domain.model.user.UserIdCode;
import com.tengju.user.domain.shared.DateUtil;
import com.tengju.user.domain.shared.IdObject;
import com.tengju.user.infrastructure.persistence.mybatis.dataobject.StarBlacklistDO;
import java.util.Optional;

public class StarBlacklistConvert {

    public static StarBlacklistDO convert(StarBlacklist starBlacklist) {
        if (null == starBlacklist) {
            return null;
        }
        return new StarBlacklistDO(Optional.ofNullable(starBlacklist.getStarBlacklistId()).map(
                IdObject::getValue).orElse(null),
                starBlacklist.getIdCode().getValue(),
                starBlacklist.getLimitStarLevel().getCode(),
                starBlacklist.getValidStatus().getCode(),
                null,
                starBlacklist.getCreateBy(),
                starBlacklist.getUpdateBy(),
                null, null);
    }

    public static StarBlacklist convert(StarBlacklistDO starBlacklistDO, String mobile) {
        if (null == starBlacklistDO) {
            return null;
        }
        return new StarBlacklist(new StarBlacklistId(starBlacklistDO.getId()),
                new UserIdCode(starBlacklistDO.getIdCode()),
                mobile,
                StarLevelEnum.parseByCode(starBlacklistDO.getLimitHighestStarLevel()),
                StarBlacklistValidStatusEnum.getByCode(starBlacklistDO.getValidStatus()),
                starBlacklistDO.getCreateBy(),
                starBlacklistDO.getUpdateBy(),
                DateUtil.dateToLocalDateTime(starBlacklistDO.getCreateTime()));
    }
}
